package com.nineclock.document.controller;

import com.nineclock.api.document.controller.PCDocumentControllerApi;
import com.nineclock.common.entity.PageResult;
import com.nineclock.common.entity.Result;
import com.nineclock.document.dto.DocFileDto;
import com.nineclock.document.dto.DocFileHistoryDto;
import com.nineclock.document.service.PCDocumentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class PCDocumentController implements PCDocumentControllerApi {
    @Autowired
    PCDocumentService pcDocumentService;
    /**
     * 分页查询文档列表
     * @param page
     * @param pageSize
     * @param keyword
     * @return
     */
    @RequestMapping("/pagingFile")
    @Override
    public Result<PageResult<DocFileDto>> pagingFile(@RequestParam(value = "page",required = false,defaultValue = "1") Integer page,
                                                     @RequestParam(value = "pageSize",defaultValue = "5",required = false) Integer pageSize,
                                                     @RequestParam(value = "keyword",required = false) String keyword) {
        PageResult<DocFileDto> result = pcDocumentService.pagingFile(page, pageSize, keyword);
        return Result.success(result);
    }

    /**
     * 更改文档权限
     * @return
     */
    @PutMapping("/{fileId}/{permission}")
    @Override
    public Result updateAuthority(@PathVariable("fileId") Long fileId, @PathVariable("permission") Short status) {
        pcDocumentService.updateAuthority(fileId, status);
        return Result.success();
    }

    /**
     * 查询文档历史记录
     * @param fileId
     * @return
     */
    @Override
    @GetMapping("/history/{fileId}")
    public Result<List<DocFileHistoryDto>> queryFileHistory(@PathVariable("fileId") Long fileId) {
        List<DocFileHistoryDto> list = pcDocumentService.queryFileHistory(fileId);
        return Result.success(list);
    }
}
